{% extends 'dns_manager/base.html' %}

{% block title %}操作日志 - DNS管理系统{% endblock %}

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
    <div>
        <h2 class="mb-1">
            <i class="bi bi-journal-text text-secondary me-2"></i>操作日志
        </h2>
        <p class="text-muted mb-0">查看系统操作记录和历史</p>
    </div>
</div>

{% if logs.object_list %}
<div class="card border-0 shadow-sm">
    <div class="card-body p-0">
        <div class="table-responsive">
            <table class="table table-hover align-middle mb-0">
                <thead class="bg-light">
                    <tr>
                        <th class="border-0 ps-4">操作</th>
                        <th class="border-0">资源</th>
                        <th class="border-0">描述</th>
                        <th class="border-0">IP地址</th>
                        <th class="border-0">时间</th>
                    </tr>
                </thead>
                <tbody>
                    {% for log in logs %}
                    <tr>
                        <td class="ps-4">
                            {% if log.action == 'create' %}
                                <span class="badge bg-success">
                                    <i class="bi bi-plus me-1"></i>创建
                                </span>
                            {% elif log.action == 'update' %}
                                <span class="badge bg-warning">
                                    <i class="bi bi-pencil me-1"></i>更新
                                </span>
                            {% elif log.action == 'delete' %}
                                <span class="badge bg-danger">
                                    <i class="bi bi-trash me-1"></i>删除
                                </span>
                            {% elif log.action == 'sync' %}
                                <span class="badge bg-info">
                                    <i class="bi bi-arrow-repeat me-1"></i>同步
                                </span>
                            {% endif %}
                        </td>
                        <td>
                            <div>
                                <div class="fw-semibold">{{ log.resource_type }}</div>
                                <small class="text-muted">ID: {{ log.resource_id }}</small>
                            </div>
                        </td>
                        <td>
                            <span class="text-muted">{{ log.description }}</span>
                        </td>
                        <td>
                            {% if log.ip_address %}
                                <code class="text-muted">{{ log.ip_address }}</code>
                            {% else %}
                                <span class="text-muted">-</span>
                            {% endif %}
                        </td>
                        <td>
                            <small class="text-muted">
                                {{ log.created_at|date:"Y-m-d H:i:s" }}
                            </small>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
    
    <!-- 分页 -->
    {% if logs.has_other_pages %}
    <div class="card-footer bg-white border-0">
        <nav aria-label="日志分页">
            <ul class="pagination pagination-sm justify-content-center mb-0">
                {% if logs.has_previous %}
                    <li class="page-item">
                        <a class="page-link" href="?page={{ logs.previous_page_number }}">
                            <i class="bi bi-chevron-left"></i>
                        </a>
                    </li>
                {% endif %}
                
                {% for num in logs.paginator.page_range %}
                    {% if logs.number == num %}
                        <li class="page-item active">
                            <span class="page-link">{{ num }}</span>
                        </li>
                    {% elif num > logs.number|add:'-3' and num < logs.number|add:'3' %}
                        <li class="page-item">
                            <a class="page-link" href="?page={{ num }}">{{ num }}</a>
                        </li>
                    {% endif %}
                {% endfor %}
                
                {% if logs.has_next %}
                    <li class="page-item">
                        <a class="page-link" href="?page={{ logs.next_page_number }}">
                            <i class="bi bi-chevron-right"></i>
                        </a>
                    </li>
                {% endif %}
            </ul>
        </nav>
    </div>
    {% endif %}
</div>
{% else %}
<div class="text-center py-5">
    <div class="mb-4">
        <i class="bi bi-journal-x text-muted" style="font-size: 4rem;"></i>
    </div>
    <h4 class="text-muted mb-3">暂无操作记录</h4>
    <p class="text-muted mb-4">
        开始使用系统后，操作记录会显示在这里
    </p>
</div>
{% endif %}
{% endblock %}